Support all ^TaskLike in do! and let! similar to F#'s task, this includes non-generic Task and ValueTask with do!#109
Merged
abelbraaksma merged 5 commits intomainfrom Nov 27, 2022
Conversation
46b3dd5 to
9985de0
Compare
…with `do!`, like `ValueTask` and non-generic `Task`
0749147 to
88f018e
Compare
Task and ValueTask with do!^TaskLike in do! and let! similar to F#'s task, this includes non-generic Task and ValueTask with do!
Member
Author
|
This PR will be part of v0.3.0. |
This was referenced Nov 27, 2022
abelbraaksma
added a commit
that referenced
this pull request
Nov 27, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #43.
Fixes #110.
This basically allows:
On top of that, this PR will add support for all of
^TaskLikethat F#'staskalso supports. This change is necessary, as the above distinction isn't possible by adding an overload for the non-genericTaskandValueTask, for the simple reason thatTask<'T> :> Task.The solution chosen in F# was to have a
Bindimplementation that takes an SRTP parameter of^TaskLike, which has aGetAwaiter() -> 'T when 'T :> ICriticalNotifyCompletion, as follows:Because
Task<'T>does have aGetAwaiteron the type, but also inheritsTaskwhich in turn implements the non-genericTaskAwaiter, a conflict arises causing an "ambiguous overload" error with just the code above. To solve this, a high-priority overloadBindforTask<'T>is added, which specifically pick theTask<'T>.GetAwaiter: unit -> TaskAwaiter<'T>, as opposed to(Task<'T> :> Task).GetAwaiter: unit -> unit.Note that the non-generic
Taskonly has the non-genericGetResult: unit -> unit, which fits the above signature where'TResult1becomesunit, and no ambiguity arises.In other words,
TaskLikeare:ValueTask,ValueTask<'T>,Task. NotTaskLikeper the above definition isTask<'T>, which has its own overload.